<template>
    <div id="background">
        <el-container>
            <el-header id="quRenZhenHeadPosition">
                <el-row type="flex" style="height:80%;display:flex;align-items: flex-end">
                    <el-col :xs="3" :sm="3" :md="3" class="imgCol">
                        <img v-bind:src="backIcon" class="backSize" @click="back"/>
                    </el-col>
                    <el-col :xs="6" :sm="6" :md="6" :offset="6" class="imgCol"> 
                        <span class="titleSize">实名认证</span>
                    </el-col>
                </el-row>
            </el-header>
            <el-main id="quRenZhenMainPosition" style="backgroundColor:#ffffff">
                <el-card class="renZhenCard" style="margin-left: 20px; margin-right: 20px; margin-top:10px;">
                    <el-row type="flex" justify="space-around">
                        <el-col :xs="6" :sm="6" :md="6" class="imgCol">
                            <span class="quRenZhenWords">真实姓名</span>
                        </el-col>
                        <el-col :xs="16" :sm="6" :md="6">
                            <el-input class="quRenZhenInput" v-model="info.realName"  clearable></el-input>
                        </el-col>
                    </el-row>
                </el-card>
                <el-card class="renZhenCard"  style="margin-left: 20px; margin-right: 20px; margin-top:10px;">
                    <el-row type="flex" justify="space-around">
                        <el-col :xs="6" :sm="6" :md="6" class="imgCol">
                            <span class="quRenZhenWords">身份证号</span>
                        </el-col>
                        <el-col :xs="16" :sm="6" :md="6">
                            <el-input class="quRenZhenInput" v-model="info.shenFenId" clearable></el-input>
                        </el-col>
                    </el-row>
                </el-card>
                <el-card class="renZhenCard"  style="margin-left: 20px; margin-right: 20px; margin-top:10px;">
                    <el-row type="flex" justify="center">
                     <el-upload
                            class="renZhenavatar-uploader"
                            action="https://jsonplaceholder.typicode.com/posts/"
                            :show-file-list="false"
                            :on-success="handleZhenSuccess"
                            >
                            <img v-if="info.imageZhenUrl" :src="info.imageZhenUrl" class="renZhenavatar">
                            <div v-else class="renZhenavatar">
                                <img src="../../assets/img/mine/quRenZhen/zhen.png"/>
                            </div>
                        </el-upload>
                        <!-- <van-uploader :after-read="afterRead" /> -->
                    </el-row>
                </el-card>
                <el-card class="renZhenCard"  style="margin-left: 20px; margin-right: 20px; margin-top:10px;">
                    <el-row type="flex" justify="center">
                     <el-upload
                            class="renZhenavatar-uploader"
                            action="https://jsonplaceholder.typicode.com/posts/"
                            :show-file-list="false"
                            :on-success="handleFanSuccess"
                            >
                            <img v-if="info.imageFanUrl" :src="info.imageFanUrl" class="renZhenavatar">
                            <div v-else class="renZhenavatar">
                                <img src="../../assets/img/mine/quRenZhen/fan.png"/>
                            </div>
                        </el-upload>
                        <!-- <van-uploader :after-read="afterRead2" /> -->
                    </el-row>
                </el-card>
            </el-main>
            <el-footer id="quRenZhenFootPosition" style="backgroundColor:#ffffff;z-index:100"> 
                <el-row type="flex" style="position:fixed;bottom:10px;width:100%">
                    <el-col class="imgCol">
                        <button v-show="ready" class="btnQuRenZhen" @click="submitRenZhenInfo">提交</button>
                        <button v-show="!ready" class="btnNotQuRenZhen">提交</button>
                    </el-col>
                </el-row>
            </el-footer>
        </el-container>
    </div>
</template>
<script>
import backIcon from '../../assets/img/mine/geRenZhongXin/back.png'
import zhenImg from '../../assets/img/mine/quRenZhen/zhen.png'
import fanImg from '../../assets/img/mine/quRenZhen/fan.png'
import { Toast} from 'vant';
export default {
    data(){
        return{
            //绑定是否上传信息完整
            ready:false,
            backIcon:backIcon,
            normalHeight:document.documentElement.clientHeight,
           
            readable:false,
      
            info:{
                realName:'',
                shenFenId:'',
                imageZhenUrl: '',
                imageFanUrl:'',
            },
            imageZhenUrl:'',
            imageFanUrl:'',
        }
    },
    watch:{
         info:{
            handler:function(){
                // console.log("info");
                // console.log(this.info);
                if(this.info.realName!=='' && this.info.shenFenId!=='' && this.info.imageZhenUrl!=='' && this.info.imageFanUrl!=='')
                {
                    this.ready=true;
                }
            },
            deep: true
        },
    },
    mounted(){
         var normalHeight=sessionStorage.getItem('normalHeight');
        var bg = document.getElementById("background");
       // normalHeight=document.documentElement.clientHeight;
        console.log("height:"+normalHeight);
        bg.style.height = normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";

        var head=document.getElementById("quRenZhenHeadPosition");
        var headHeight=normalHeight/30 *4 ;
        console.log("headHeight:"+headHeight);
        head.style.height=headHeight+"px";

        // var main=document.getElementById("quRenZhenMainPosition");
        // var mainHeight=normalHeight/30 *23;
        // console.log("mainHeight:"+mainHeight);
        // main.style.height=mainHeight+"px";

        
        // var bottom=document.getElementById("quRenZhenFootPosition");
        // var botHeight=normalHeight/30 *3;
        // console.log("btnHeight:"+botHeight);
        // bottom.style.height=botHeight+'px';
    },
    methods:{
        back(){
            console.log("back:");
            this.$router.go(-1);
        },
        handleZhenSuccess(res, file) {
            this.info.imageZhenUrl = URL.createObjectURL(file.raw);
            this.imageZhenUrl=file.raw;
            console.log(res);
            console.log(file);
        },
        handleFanSuccess(res, file) {
            this.info.imageFanUrl = URL.createObjectURL(file.raw);
            this.imageFanUrl=file.raw;
        },
        afterRead(file) {
            // 此时可以自行将文件上传至服务器
            console.log(file);
            },
        afterRead2(file) {
            // 此时可以自行将文件上传至服务器
            console.log(file);
            },
        //提交实名认证请求
        submitRenZhenInfo(){
            var URL=this.IP.IP+'/user/certification';
            console.log(URL);
            // console.log(this.imageZhenUrl);
            // console.log(this.imageFanUrl);
            var form = new FormData();
            form.append('front',this.imageZhenUrl);
            form.append('behind',this.imageFanUrl);
            form.append('realname',this.info.realName);
            form.append('id',this.info.shenFenId);
            console.log(form);
            this.$ajax({
                method:'post',
                url:URL,
                data:form,
                headers:{
                    'Content-type':'multipart/form-data'
                }
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    Toast(response.data.data);
                 
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        }
    }
    
}
</script>
<style>
.el-main,.el-header,.el-footer{
    padding: 0px ;
}
#quRenZhenHeadPosition{
    background-color: #53cdf5;
}
.renZhenCard .el-card__body {
    padding: 5px;
}
.quRenZhenWords{
    color: #707070;
}
.quRenZhenInput .el-input__inner {
    border: none;
    border-bottom: 1px solid;
    border-color: #F0F0F0;
    background-color: rgba(255, 255, 255, 0);
    color: #707070;
    border-radius: 0px;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
  .renZhenavatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .renZhenavatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .renZhenavatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 340px;
    height: 220px;
    line-height: 220px;
    text-align: center;
  }
  .renZhenavatar {
    width: 340px;
    height: 220px;
    display: block;
  }
  .btnNotQuRenZhen{
    border:#E0E0E0 1px solid;
    background-color: #E0E0E0;
    color: #707070;
    font-size: 1.125em;
    width: 80%;
    height: 40px;
    outline: none;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    -ms-border-radius: 25px;
    -o-border-radius: 25px;
    border-radius: 25px;
  }
  .btnQuRenZhen{
    border:#53cdf5 1px solid;
    background-color: #53cdf5;
    color: #fff;
    font-size: 1.125em;
    width: 80%;
    height: 40px;
    outline: none;
    -webkit-border-radius: 25px;
    -moz-border-radius: 25px;
    -ms-border-radius: 25px;
    -o-border-radius: 25px;
    border-radius: 25px;
  }
.backSize{
    height: 26px;
}
.titleSize{
    font-size:1.125em;
    color:#ffffff
}
@media screen and (max-height: 600px){
  .backSize{
      height: 22px;
  }
  .titleSize{
      font-size: 1em;
  }
   .renZhenavatar-uploader-icon {
       height: 120px;
       line-height: 120px;
  }
    .renZhenavatar {
        height: 120px;
  }

}
@media screen and (min-height: 800px){
   .renZhenavatar-uploader-icon {
        height: 180px;
        line-height: 180px;
  }
    .renZhenavatar {
        height: 180px;
  }

}
@media screen and (max-width: 340px){
   .renZhenavatar-uploader-icon {
        width: 260px;
  }
   .renZhenavatar {
        width: 260px;
  }
  
}
</style>
